home *** CD-ROM | disk | FTP | other *** search
- /* getpixel.c */
- /* Entered by A. Wayner */
-
- # include <graphics.h>
-
- main()
- {
- int graphdriver = DETECT;
- int graphmode, x, y, color;
-
- /* Detect adapter type and */
- /* initialize graphics system */
- initgraph( &graphdriver, &graphmode, "\\turboc");
- outtextxy( 10, 10, "Changing colors using getpixel with putpixel ");
-
- /* Draw a red bordered rectangle */
- setcolor( RED );
- rectangle( 70, 50, 130, 80 );
- outtextxy( 10,20,"Press any key to turn red into blue " );
- getch();
-
- /* Go over a rectangular region and */
- /* change red to blue */
- for( x = 50; x < 150; x++ )
- {
- for( y = 40; y < 90; y++ )
- {
- if( getpixel(x,y)==0 ) /* It's background */
- {
- putpixel(x,y,RED); /* Turn pixel red */
- continue; /* skip next check */
- }
-
- if( getpixel(x,y)==RED) /* It's a red pixel */
- {
- putpixel(x,y,BLUE ); /* Turn pixel blue */
- }
- }
- }
-
- outtextxy( 10, getmaxy() - 30,"Press any key to exit : ");
-
- getch(); /* Wait until a key is pressed */
- closegraph(); /* Exit graphics library */
-
- }